package com.yht.weblog.admin.controller;

import com.yht.weblog.admin.model.vo.article.*;
import com.yht.weblog.admin.service.AdminArticleService;
import com.yht.weblog.common.aspect.ApiOperationLog;
import com.yht.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yht
 * @date: 2024/1/2 23:10
 * @description:
 **/
@RestController
@RequestMapping("/admin")
@Api(tags = " Admin 文章管理")
public class AdminArticleController {

    @Autowired
    private AdminArticleService adminArticleService;

    /**
     * 发布文章
     * @param publishArticleReqVO
     * @return
     */
    @PostMapping("/article/publish")
    @ApiOperation(value = "发布文章")
    @ApiOperationLog(description = "发布文章")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response publishArticle(@RequestBody @Validated PublishArticleReqVO publishArticleReqVO){
        return adminArticleService.publishArticle(publishArticleReqVO);
    }

    /**
     * 删除文章
     * @param deleteArticleReqVO
     * @return
     */
    @PostMapping("/article/delete")
    @ApiOperation(value = "删除文章")
    @ApiOperationLog(description = "删除文章")
    public Response deleteArticle(@RequestBody @Validated DeleteArticleReqVO deleteArticleReqVO){
        return adminArticleService.deleteArticle(deleteArticleReqVO);
    }

    /**
     * 查询文章分页数据
     * @param findArticlePageListReqVO
     * @return
     */
    @PostMapping("/article/list")
    @ApiOperation(value = "查询文章分页数据")
    @ApiOperationLog(description = "查询文章分页数据")
    public Response findArticlePageList(@RequestBody @Validated FindArticlePageListReqVO findArticlePageListReqVO){
        return adminArticleService.findArticlePageList(findArticlePageListReqVO);
    }

    /**
     * 查询文章详情
     * @param findArticleDetailReqVO
     * @return
     */
    @PostMapping("/article/detail")
    @ApiOperation(value = "查询文章详情")
    @ApiOperationLog(description = "查询文章详情")
    public Response findArticleDetail(@RequestBody @Validated FindArticleDetailReqVO findArticleDetailReqVO){
        return adminArticleService.findArticleDetail(findArticleDetailReqVO);
    }

    /**
     * 更新文章
     * @param updateArticleReqVO
     * @return
     */
    @PostMapping("/article/update")
    @ApiOperation(value = "更新文章")
    @ApiOperationLog(description = "更新文章")
    public Response updateArticle(@RequestBody @Validated UpdateArticleReqVO updateArticleReqVO){
        return adminArticleService.updateArticle(updateArticleReqVO);
    }

}
